package com.rd.student.ruanjian.class3.gaochenxi.LianXi1.stringPractice;

public class StringPrac {
      public static void main(String[] args) {
            String str = "aaaaaaabbbbbcerrrrggggggggsssssspoqqqqq";
            String s = returnString(str);
            System.out.println(s);
      }

      public static String returnString(String str) {
            StringBuilder stringBuilder = new StringBuilder();
            int[] result = new int[26];
            for (int i = 0; i < 26; i++) {
                  result[str.charAt(i) - 'a']++;
            }
            char a = 'a';
            for (int i = 0; i < result.length; i++) {
                  if (result[i] == 1) {
                        stringBuilder.append((char) ('a' + i));//拼接字母就可以
                  } else if (result[i] > 1) {
                        //StringBuilder方式拼接
                        stringBuilder.append((char) ('a' + i));
                        stringBuilder.append(result[i]);
                  }
            }
            return stringBuilder.toString();
      }
}
